#include "common.h"

#ifndef PROBE

void timer0Overflow()
{
	//debug("timer 0 overflow\n");	
	
	Timer0Reg0++;// increment low-order counter

	
	if (Timer0Reg0 == 2) //send fpga packet time
	{
		flagset(flags, FLAG_SEND_GRAPH);
		Timer0Reg0 = 0;
		
	}
}
void timer1Overflow(void)
{
	Timer1Reg0++;			// increment low-order counter
	//printf("timer 1 overflow\n");

	if (Timer1Reg0 == 50)
	{
		Timer1Reg0 = 0;
		//timer1Overflow();
	}
}

void init_mcu(void)
{
	fpga_packet[0] = PACKET_GRAPH;
	u08 i;

	for(i = 1; i < FPGA_PACKET_LEN; i++) 
		fpga_packet[i] = 0;
	
	_delay_ms(50); //give the rf time to power up
	init_rf();
	//init_ADC();
}
void init_rf(void)
{
	//power on RF module from pin, hah
	RFDDR |= _BV(RFGNDPIN);
	cbi(RFPORT, RFGNDPIN);
	_delay_ms(100); //give the rf time to power up

	//PCMSK1 |= _BV(PCINT12); //select the pin for change interrupt
	//EIMSK |= _BV(PCIE1); //enable pin change interrupt on group
	
	//configure_transmitter();
	configure_receiver();
}
void lambdaboard(void)
{

	error_handler();
	flag_handler();
	if((RFPIN & _BV(RX_DR))) {
	  // _delay_ms(10);
	   if(RFPIN & _BV(RX_DR))
	   {
			packet_recv_rf();
			packet_rf_handler();
		//_delay_ms(500);
		}
	}

	return;
}

#endif
